<?php

	// +----------------------------------------------------------------------
	// | 用户组
	// +----------------------------------------------------------------------
	// | Copyright (c) 2015-2024 http://www.yicmf.com, All rights reserved.
	// +----------------------------------------------------------------------
	// | Author: 微尘 <yicmf@qq.com>
	// +----------------------------------------------------------------------

	namespace app\event\ucenter;

	use app\common\event\Base;
	use app\model\ucenter\UserGrade as UserGradeModel;

	class UserGrade extends Base
	{

		/**
		 * 新增|更新用户组
		 * @param      $param
		 * @param null $user
		 * @return mixed
		 * @author  : 微尘 <yicmf@qq.com>
		 * @datetime: 2019/3/25 16:15
		 */
		public function update($param, $user = null)
		{
			try {
				if (!empty($param['id'])) {
					$group = UserGradeModel::get($param['id']);
				} else {
					$group = new UserGradeModel();
				}
				$group['name'] = $param['name'];
				$group['title'] = $param['title'];
				$group['description'] = $param['description'];
				$group['experience'] = $param['experience'];
				if (!$group->save()) {
					throw new \Exception('数据储存失败');
				}
				$data['data'] = $group;
				$data['code'] = 0;
			} catch (\Exception $e) {
				$data['code'] = 1;
				$data['message'] = $e->getMessage();
			}
			return $data;
		}
	}
